//
//  BindCardCell.m
//  Rabbit
//
//  Created by 阿帕 on 2018/11/9.
//  Copyright © 2018年 GCY. All rights reserved.
//

#import "BindCardCell.h"



@interface BindCardCell ()
@property (weak, nonatomic) IBOutlet UIImageView *cardIcon;
@property (weak, nonatomic) IBOutlet UILabel *cardNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *bankNameLabel;
@property (weak, nonatomic) IBOutlet UIView *line;
@property (weak, nonatomic) IBOutlet UILabel *bindCardStatus;
@property (strong, nonatomic) IBOutlet UILabel *bangCarTitLabel;
@property (strong, nonatomic) IBOutlet UIView *bottomView;

@end

@implementation BindCardCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _cardNumLabel.textColor = Light_TextColor;
    _bankNameLabel.textColor = Dark_TextColor;
    _line.backgroundColor = BackgroundColor;
}

- (void)setModel:(BankCardListModel *)model {
    
    _model = model;
    
//    setNetImage(_cardIcon, model., <#imgName#>)
    if ([CJStringWithFormat(@"%ld",(long)model.isDefault) isEqual:@"1"]) {
        _cardNumLabel.text = CJStringWithFormat(@"%@ - %@(默认)", model.name, model.account);
    } else {
        _cardNumLabel.text = CJStringWithFormat(@"%@ - %@", model.name, model.account);
    }
    _bankNameLabel.text = CJStringWithFormat(@"%@", model.bankName);
    
    //云企付绑卡状态:0:默认未绑卡，1：绑卡中，2：待验证，3：已成功，4：已失败"
    //  bindCardStatus;
    NSString *strBindCardStatus = @"";
    NSString *colorHex = @"#FF4444";
    switch (model.bindCardStatus) {
        case 0:
//            strBindCardStatus = @"未绑卡";
            strBindCardStatus = @" 待审核";
            break;
        case 1:
//            strBindCardStatus = @"处理中";
            strBindCardStatus = @" 待审核";
            break;
        case 2:
//            strBindCardStatus = @"待验证";
            strBindCardStatus = @" 待审核";
            break;
        case 3:
            strBindCardStatus = @"已绑卡";
            colorHex = @"#02A7F0";
            break;
        case 4:
            strBindCardStatus = CJStringWithFormat(@"已失败,%@", model.bindCardFailReason);
            break;
        default:
            break;
    }
    NSArray *titleArr ;
    if (model.isDefault == 1) {
        titleArr = @[@"编辑",@"绑卡",@"解绑",@"删除"];
    }else{
        titleArr = @[@"编辑",@"默认",@"绑卡",@"解绑",@"删除"];
    }
    [self.bottomView removeAllSubviews];
    for (int i = 0; i < titleArr.count ; i++) {
        UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [btn setTitle:titleArr[i] forState:(UIControlStateNormal)];
        [btn setFrame:CGRectMake(i * 65 + 10 * (i + 1), 2.5, 65, 30)];
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 10;
        if ([titleArr[i] isEqualToString:@"默认"]) {
            btn.backgroundColor = [UIColor colorWithHexString:@"#349DE5"];
        }else if ([titleArr[i] isEqualToString:@"编辑"]){
            btn.backgroundColor = [UIColor colorWithHexString:@"#F5B51B"];
        }else if ([titleArr[i] isEqualToString:@"绑卡"]){
            btn.backgroundColor =  [UIColor colorWithHexString:@"#13ABBE"];
        }else if ([titleArr[i] isEqualToString:@"解绑"]){
            btn.backgroundColor = [UIColor colorWithHexString:@"#F5B51B"];
        }else if ([titleArr[i] isEqualToString:@"删除"]){
            btn.backgroundColor =  [UIColor colorWithHexString:@"E05147"];
        }
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.bottomView addSubview:btn];
    }
    _bindCardStatus.text = strBindCardStatus;
    _bindCardStatus.hidden = YES;
    _bangCarTitLabel.hidden = YES;
    _bindCardStatus.textColor = [UIColor colorWithHexString:colorHex];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)btnAction:(UIButton *)btn{
    self.buttonTitleBlock(btn.titleLabel.text);
}
@end
